﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Dynamic;
using System.ComponentModel;
using CCH.Entity;

namespace CCH.DAO
{
    [DataObject(true)]
    public class doctorprofileDAO
    {
        private Entities model = new Entities();

        public IQueryable<doctorprofile> Get_doctor_AllData()
        {
            return from d in model.doctorprofile
                   where d.state == "1"
                   orderby d.doc_order
                   select d;
        }

        public IQueryable<doctorprofile> Get_doctor_AllData(int startRowIndex, int maximumRows)
        {
            return Get_doctor_AllData().Skip(startRowIndex).Take(maximumRows);
        }

        public int Get_doctor_AllData_Count()
        {
            return Get_doctor_AllData().Count();
        }

        public doctorprofile Get_doctorprofile(int doc_no)
        {
            return (from d in model.doctorprofile where d.doc_no == doc_no select d).FirstOrDefault();
        }

        public void Add_doctorprofile(doctorprofile d)
        {
            model.doctorprofile.AddObject(d);
            Update();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc_no"></param>
        /// <param name="peo_uid">登入人員UID</param>
        public void Delete_doctorprofile(int doc_no,int peo_uid)
        {
            doctorprofile d = Get_doctorprofile(doc_no);
            d.state = "2";
            d.createuid = peo_uid;
            d.createtime = DateTime.Now;
            Update();
        }

        public void Update()
        {
            model.SaveChanges();
        }

    }
}
